﻿// Study1014.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第十章 STL和泛型设计 函数对象 二元谓词

#include <iostream>
#include <functional>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int intArr[] = { 30,90,10,40,70,50,20,80 };
    const int N = sizeof(intArr) / sizeof(int);
    vector<int> a(intArr, intArr + N);
    cout << "before sorting : " << endl;
    copy(a.begin(), a.end(), ostream_iterator<int>(cout, " "));
    cout << endl;
    cout << "====================================================" << endl;

    sort(a.begin(), a.end(), greater<int>());

    cout << "after sorting : " << endl;
    copy(a.begin(), a.end(), ostream_iterator<int>(cout, " "));
    cout << endl;
    cout << "====================================================" << endl;
    auto p = find_if(a.begin(), a.end(), bind2nd(greater<int>(), 40));
    if (p==a.end())
    {
        cout << "no element greater than 40" << endl;

    }
    else
    {
        cout << "first element greater than 40 is:" << *p << endl;
    }
    return 0;
}


